<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>router</title>
    <!-- 导入 vue 文件 -->
    <script src="js/vue.js"></script>
    <script src="js/vue-router.js"></script>
</head>

<body>
    <!-- 被 vm 实例所控制的区域 -->
    <div id="app">
        <router-link to="/user">User</router-link>
        <router-link to="/register">Register</router-link>

        <!-- 路由占位符 -->
        <router-view></router-view>
    </div>

    <script>
        const User = {
            template: '<h1>User 组件</h1>'
        }

        const Register = {
            template: '<h1>Register 组件</h1>'
        }

        // 创建路由实例对象
        const router = new VueRouter({
            // 所有路由规则
            routes: [
                { path: "/", redirect: "/user" },
                { path: '/user', component: User },
                { path: '/register', component: Register }
            ]
        })

        // 创建 vm 实例对象
        const vm = new Vue({
            // 指定控制的区域
            el: '#app',
            data: {},
            // 挂载路由实例对象
            router
        })
    </script>
</body>

</html>